package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcOrderInfo;
import com.lxmes.business.service.ICcOrderInfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 订单信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-27
 */
@RestController
@RequestMapping("/business/orderinfo")
public class CcOrderInfoController extends BaseController
{
    @Autowired
    private ICcOrderInfoService ccOrderInfoService;

    /**
     * 查询订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:orderinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcOrderInfo ccOrderInfo)
    {
        startPage();
        ccOrderInfo.setDeptId(SecurityUtils.getDeptId());
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoList(ccOrderInfo);
        return getDataTable(list);
    }
    @GetMapping("/getOrderinfoList")
    public AjaxResult getOrderinfoList()
    {
        CcOrderInfo ccOrderInfo=new CcOrderInfo();
        ccOrderInfo.setDeptId(SecurityUtils.getDeptId());
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoList(ccOrderInfo);
        return AjaxResult.success(list);
    }

    /**
     * 导出订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:orderinfo:export')")
    @Log(title = "订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcOrderInfo ccOrderInfo)
    {
        ccOrderInfo.setDeptId(SecurityUtils.getDeptId());
        List<CcOrderInfo> list = ccOrderInfoService.selectCcOrderInfoList(ccOrderInfo);
        ExcelUtil<CcOrderInfo> util = new ExcelUtil<CcOrderInfo>(CcOrderInfo.class);
        util.exportExcel(response, list, "订单信息数据");
    }

    /**
     * 获取订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:orderinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccOrderInfoService.selectCcOrderInfoById(id));
    }

    /**
     * 新增订单信息
     */
    @PreAuthorize("@ss.hasPermi('business:orderinfo:add')")
    @Log(title = "订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcOrderInfo ccOrderInfo)
    {    ccOrderInfo.setDeptId(SecurityUtils.getDeptId());
        return toAjax(ccOrderInfoService.insertCcOrderInfo(ccOrderInfo));
    }

    /**
     * 修改订单信息
     */
    @PreAuthorize("@ss.hasPermi('business:orderinfo:edit')")
    @Log(title = "订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcOrderInfo ccOrderInfo)
    {
        return toAjax(ccOrderInfoService.updateCcOrderInfo(ccOrderInfo));
    }

    /**
     * 删除订单信息
     */
    @PreAuthorize("@ss.hasPermi('business:orderinfo:remove')")
    @Log(title = "订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccOrderInfoService.deleteCcOrderInfoByIds(ids));
    }
}
